package com.mmsj;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;


public class MyDBHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "fDB.db";
    private static final int DATABASE_VERSION = 1;

    private static MyDBHelper helper;


    public static MyDBHelper getInstance(Context context) {
        if (helper == null) {
            helper = new MyDBHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
        return helper;
    }

   public MyDBHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, DATABASE_NAME, factory, DATABASE_VERSION);
    }

    // 首次创建数据库时调用，在该方法中创建表
    @Override
    public void onCreate(SQLiteDatabase db) {
        // 创建表
        String sql = "create table if not exists user(id integer primary key autoincrement,username text,password text,phone text)";
        db.execSQL(sql);
        Log.d("my-log","user表创建成功");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
